package de.tabuma.pm.project.controller;

import de.tabuma.pm.project.controller.list;
import de.tabuma.pm.project.entity.Project;
import de.tabuma.pm.project.logik.ProjectFacade;
import de.tabuma.lib.*;
import de.tabuma.pm.*;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.google.appengine.api.users.*;

/**
 *
 * @author alefen
 */
public class remove extends tabumacontroller {

    public remove(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void navigate(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        if(request.getParameter(constants.paramProjectRemove)!=null) {

            UserService userService = UserServiceFactory.getUserService();
            User user = userService.getCurrentUser();

            String id = request.getParameter(constants.projectId);
            int intId = Integer.valueOf(id).intValue();
            Project project = ProjectFacade.get(intId);
            ProjectFacade.remove(intId, user.getEmail());
            request.setAttribute(constants.paramAction, "" + constants.ACTION_LIST);
            list lpc = new list(this.getServlet(), this.getParameter());
            lpc.navigate(context, request, response, out);
        }
        else {
            request.setAttribute(constants.paramAction, "" + constants.ACTION_REMOVE);
            String id = request.getParameter(constants.projectId);
            if(id!=null) {
                int idInt = Integer.valueOf(id).intValue();
                Project project = ProjectFacade.get(idInt);
                request.setAttribute(constants.paramProject, project);
            }
        }

    }
    
}
